package THREAD.homework;
    /*
    4)、编写10个线程，第一个线程从1加到10，
    第二个线程从11加到20,…第十个线程从91加到100，
    最后再把10个线程结果相加。
     */
public class homework04 extends Thread {

        private int staNum;
        public static int sum;

        public homework04(int staNum) {
            this.staNum = staNum;
        }

        public static synchronized void add(int num) {
            sum += num;
        }

        @Override
        public void run() {
            int sum = 0;
            for (int i = 0; i < 10; i++) {
                sum += staNum + i;
            }
            add(sum);
        }

        public static void main(String[] args) throws InterruptedException {
            Thread[] threadList = new Thread[10];
            for (int i = 0; i < 10; i++) {
                threadList[i] = new homework04(10*i+1);
                threadList[i].start();
            }
            for (int i = 0; i < 10; i++) {
                threadList[i].join();
            }
            System.out.println("Sum is : " + sum);
        }
    }